{include file="header.html"}
<script type="text/javascript" src="/wl_admin/includes/javascript/additional-methods.js"></script>
<script type="text/javascript">
<!-- {if $customer.customer_id} -->
var ajax_url = 'index.php?app=customer&act=check_customer&customer_id={$customer.customer_id}&ajax=1';
<!--{else}-->
var ajax_url = 'index.php?app=customer&act=check_customer&ajax=1';
<!-- {/if} -->
//<!CDATA[
$(function(){
  $('#return_time').datepicker({dateFormat: 'yy-mm-dd',changeMonth: true,changeYear: true});  
    $('#customer_form').validate({
        errorPlacement: function(error, element){
            $(element).next('.field_notice').hide();
            $(element).after(error);
        },
        onkeyup:true,
        submitHandler:function(form){
          var source=$('#source_type').val(),
                user_name=$('#user_name').val(),
                customer_name=$('#customer_name').val(),
                customer_ugrade=$('#customer_ugrade').val(),
                company=$('#company').val(),
                phone_mob=$('#phone_mob').val(),
                email=$('#email').val(),
                im_qq=$('#im_qq').val(),
                city=$('#city').val(),
                address=$('#address').val();
            $.ajax({
              type: "POST",
              url: "",
              data: {'source':source,'user_name':user_name,'customer_name':customer_name,'customer_ugrade':customer_ugrade,'company':company,'phone_mob':phone_mob,'email':email,'im_qq':im_qq,'city':city,'address':address},
              dataType: "json",
              success:function(jdata){
                if(jdata.state){
                    window.location.href='index.php?app=customer';
                }
                else{
                    alert(jdata.msg);
                }
              }
            });
        } ,
        success: function(label){
            label.addClass('right').text('OK!');
        },
        rules : {
		user_name : {
                required : true,
                remote   : {
                    url :ajax_url,
                    type:'get',
                    data:{
                        'user_name' : function(){
                            return $('#user_name').val();
                        },
                        'source':function(){
                            return $('#source_type').val();
                        }
                    }
                }
            },
            phone_mob_1 : {
                required : true,
                minlength :11,
                maxlength :11,
		    remote   : {
                    url :ajax_url,
                    type:'get',
                    data:{
                        'phone_mob' : function(){
                            return $('#phone_mob').val();
                        },
                        'source':function(){
                            return $('#source_type').val();
                        }
                    }
                }
            },
            phone_mob_2 : {
                either_of : true,
                minlength :11,
                maxlength :11,
                remote   : {
                    url :ajax_url,
                    type:'get',
                    data:{
                        'phone_mob' : function(){
                            return $('#phone_mob').val();
                        },
                        'source':function(){
                            return $('#source_type').val();
                        }
                    }
                }
            },
            im_qq2 : {
              either_of : true,
              remote   : {
                    url :ajax_url,
                    type:'get',
                    data:{
                        'im_qq' : function(){
                            return $('#im_qq').val();
                        },
                        'source':function(){
                            return $('#source_type').val();
                        }
                    }
                }
            }
        },
        messages : {
            user_name : {
                required : '会员名称不能为空',
		    remote   : '该会员名称已经存在,请重新填写!'
            },
            phone_mob_1 : {
                required   : '手机号码不能为空',
                minlength : '请输入正确的手机号码',
                maxlength : '请输入正确的手机号码',
		    remote   : '该手机号码已经存在,请重新填写!'
            },
            phone_mob_2 : {
                either_of : '手机号码和qq不能同时为空',
                minlength : '请输入正确的手机号码',
                maxlength : '请输入正确的手机号码',
                remote : '该手机号码已经存在,请重新填写!'
            },
            im_qq2 : {
              either_of : '手机号码和qq不能同时为空',
              remote : 'qq号码已存在，请重新填写'
            }
        }
    });
	
    $('#source_type').bind('change',function(){
      var source_v=$(this).val();
      if(source_v == '1' || source_v == '4'){
        $('#user_name').attr('name','user_name').removeClass('error').next('label').hide();
        $('#phone_mob').attr('name','phone_mob').removeClass('error').next('label').hide();
        $('#im_qq').attr('name','im_qq').removeClass('error').next('label').hide();
      }else if(source_v == '2' || source_v == '3'){
        $('#user_name').attr('name','user_name_1').removeClass('error').next('label').hide();
        $('#phone_mob').attr('name','phone_mob_1').removeClass('error').next('label').hide();
        $('#im_qq').attr('name','im_qq1').removeClass('error').next('label').hide();
      }else{
        $('#user_name').attr('name','user_name_2').removeClass('error').next('label').hide();
        $('#phone_mob').attr('name','phone_mob_2').removeClass('error').next('label').hide();
        $('#im_qq').attr('name','im_qq2').removeClass('error').next('label').hide();
      }
    });
	
	$('#source_type').change();
});
//]]>
</script>
<div id="rightTop">
  <p>客户关系管理</p>
  <ul class="subnav">
    <li>
      <a class="btn1" href="index.php?app=customer">客户管理</a>
    </li>
    <!-- {if $customer.customer_id} -->
    <li>
      <a class="btn1" href="index.php?app=customer&amp;act=add">新增客户</a>
    </li>
    <!-- {else} -->
    <li>
      <span>新增客户</span>
    </li>
    <!-- {/if} --> </ul>
</div>
<div class="info">
  <form method="post" id="customer_form">
    <table class="infoTable">
      <tr>
        <th class="paddingT15">资料来源:</th>
        <td class="paddingT15 wordSpacing5">
          <select class="querySelect" name="source" id="source_type">
            {html_options options=$cfg_customer.source selected=$customer.source}
          </select>
        </td>
      </tr>
      <tr>
        <th class="paddingT15">会员名称:</th>
        <td class="paddingT15 wordSpacing5">
          <input class="infoTableInput2" type="text" name="user_name" id="user_name" value="{$customer.user_name}" />
        </td>
      </tr>
       <tr>
        <th class="paddingT15">客户姓名:</th>
        <td class="paddingT15 wordSpacing5">
          <input class="infoTableInput2" type="text" name="customer_name" id="customer_name" value="{$customer.customer_name}" />
        </td>
      </tr>
      <tr>
        <th class="paddingT15">客户等级:</th>
        <td class="paddingT15 wordSpacing5">
          <select class="querySelect" name="customer_ugrade" id="customer_ugrade">
            {html_options options=$cfg_customer.customer_ugrade selected=$customer.customer_ugrade}
          </select>
        </td>
      </tr>
      <tr>
        <th class="paddingT15">公司名称:</th>
        <td class="paddingT15 wordSpacing5">
          <input class="infoTableInput2" type="text" name="company" id="company" value="{$customer.company}" />
        </td>
      </tr>
      <tr>
        <th class="paddingT15">手机:</th>
        <td class="paddingT15 wordSpacing5">
          <input class="infoTableInput2" type="text" {if $customer.source eq 2 or $customer.source eq 3} name="phone_mob_1"{else} name="phone_mob"{/if} id="phone_mob" value="{$customer.phone_mob}" />
        </td>
      </tr>
      <tr>
        <th class="paddingT15">E-MALL:</th>
        <td class="paddingT15 wordSpacing5">
          <input class="infoTableInput2" type="text" name="email" id="email" value="{$customer.email}" />
        </td>
      </tr>
      <tr>
        <th class="paddingT15">QQ:</th>
        <td class="paddingT15 wordSpacing5">
          <input class="infoTableInput2" type="text" name="im_qq" id="im_qq" value="{$customer.im_qq}" />
        </td>
      </tr>
      <tr>
        <th class="paddingT15">城市:</th>
        <td class="paddingT15 wordSpacing5">
          <input class="infoTableInput" type="text" name="city" id="city" value="{$customer.city}" />
        </td>
      </tr>
      <tr>
        <th class="paddingT15">地址:</th>
        <td class="paddingT15 wordSpacing5">
          <input class="infoTableInput" type="text" name="address" id="address" value="{$customer.address}" />
        </td>
      </tr>
      <tr>
        <th></th>
        <td class="ptb20">
          <input class="formbtn" type="submit" name="Submit" value="{$lang.submit}" />
          <input class="formbtn" type="reset" name="Submit2" value="{$lang.reset}" />
          <input class="formbtn" type="button" onclick="javascript:history.back();" value="返回" />
        </td>
      </tr>
    </table>
  </form>
</div>
{include file="footer.html"}